import axios from 'axios'
import { BASE_URL, TIME_OUT } from './config'

const LFRequest = (options, url, params, headers = {}) => {
  return new Promise((resolve, reject) => {
    axios.request({
      baseURL: '/api',
      timeout: TIME_OUT,
      method: options,
      url,
      params,
      header: {
        "Content-type":
          headers.dataType == 'FORM' ?
            'application/x-www-form-urlencoded' :
            'application/json;charset=UTF-8'
      }
    }).then(res => {
      resolve(res.data)
    }).catch(err => {
      reject(err)
      console.log(err, '33333333333')
    })
  })
}

export const get = (url, params, headers = {}) => {
  return LFRequest('GET', url, params, headers)
}
export const post = (url, params, headers = {}) => {
  return LFRequest('post', url, params, headers)
}
export const patch = (url, params, headers = {}) => {
  return LFRequest('patch', url, params, headers)

}
export const put = (url, params, headers = {}) => {
  return LFRequest('put', url, params, headers)

}
export const del = (url, params, headers = {}) => {
  return LFRequest('del', url, params, headers)
}
